package com.crazypos.common.utils;

import com.crazypos.constant.CommonConstant;
import com.crazypos.security.entity.UserDetailEntity;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtil {
    /**
     * 私有化构造器
     */
    private SecurityUtil() {
    }

    /**
     * 获取当前用户信息
     */
    public static UserDetailEntity getUserInfo() {
        UserDetailEntity userDetails = (UserDetailEntity) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return userDetails;
    }

    /**
     * 获取当前用户ID
     */
    public static String getUserId() {
        return getUserInfo().getId();
    }

    /**
     * 获取当前用户账号
     */
    public static String getUserName() {
        return getUserInfo().getUsername();
    }

    /***
     * 获取当前用户机构ID
     */
    public static String getOrganizationId() {
        return getUserInfo().getOrganizationId();
    }

    /**
     * 生成 redis 的 权限key
     *
     * @return
     */
    public static String createPermissionKey(String organizationId, String roleId) {
        return CommonConstant.REDIS_ROLE_PREFIX + ":"
//                + organizationId + "_"
                + roleId;
    }
}
